package com.zrc.japktool.apk.jiagu;

import com.zrc.japktool.util.CmdUtil;
import com.zrc.japktool.util.TaskLog;
import com.zrc.japktool.util.Zip4jUtil;

import java.io.File;

public class jar2Dex {
    public static void main(String[] args) throws Exception {
        File aar = new File("C:/Users/15666/IdeaProjects/JApkTool/doc/jiagu/CLib-release.aar");
        File d8Jar = new File("C:/Users/15666/IdeaProjects/JApkTool/doc/jiagu/d8.jar");
        File classesZip = new File("C:/Users/15666/IdeaProjects/JApkTool/doc/jiagu/classes.zip");
        File classesJar = new File("C:/Users/15666/IdeaProjects/JApkTool/doc/jiagu/classes.jar");
        if (classesZip.exists()) {
            classesZip.delete();
        }
        if (classesJar.exists()) {
            classesJar.delete();
        }
        Zip4jUtil.extractFile(aar.getAbsolutePath().replace("\\","/"),"classes.jar",aar.getParent().replace("\\","/"));

        Zip4jUtil.extractDir(aar.getAbsolutePath().replace("\\","/"),"jni/",aar.getParent().replace("\\","/"));

        StringBuilder sb=new StringBuilder();
        sb.append("cmd /c  java -jar "+d8Jar.getAbsolutePath().replace("\\", "/"));
        //sb.append("--min-api 26 ");
        sb.append(" --output "+classesZip.getAbsolutePath().replace("\\","/"));
        sb.append(" "+classesJar.getAbsolutePath().replace("\\","/"));

        CmdUtil.exec(sb.toString(), TaskLog.newTaskLog());
        Zip4jUtil.extractFile(classesZip.getAbsolutePath().replace("\\","/"),"classes.dex",d8Jar.getParent().replace("\\","/"));
        if (classesZip.exists()) {
            classesZip.delete();
        }
        if (classesJar.exists()) {
            classesJar.delete();
        }
    }

}
